package com.github.niefy.modules.wx.handler;
import com.github.niefy.modules.wx.service.MsgReplyService;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
import me.chanjar.weixin.mp.util.WxMpConfigStorageHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;
/**
 * @author Binary Wang
 */
@Component
public class MenuHandler extends AbstractHandler {
  @Autowired
  MsgReplyService msgReplyService;
  @Override
  public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService weixinService, WxSessionManager sessionManager) {
    if (WxConsts.EventType.VIEW.equals(wxMessage.getEvent())) {
      return null;
    }
    String appid = WxMpConfigStorageHolder.get();
    logger.info("菜单事件：" + wxMessage.getEventKey());
    msgReplyService.tryAutoReply(appid, true, wxMessage.getFromUser(), wxMessage.getEventKey());
    return null;
  }
}
